﻿using System;

namespace DotNetNeural.Metric
{
    public class DefaultDeviation : IDeviation
    {
        #region IDeviation Members

        public float CalculateDeviation(float[] lhs, float[] rhs)
        {
            if (lhs == null || rhs == null)
                throw new NullReferenceException("Illegal null-reference args");

            int size = lhs.Length;
            if (size != rhs.Length)
                throw new ArgumentException("Arrays must have the same size");

            float result = 0;

            for (int i = 0; i < size; ++i)
            {
                result += (lhs[i] - rhs[i]) * (lhs[i] - rhs[i]);
            }

            return (float)Math.Sqrt(result / size);
        }

        #endregion
    }
}
